#pragma once

#include "comm/znx_pool.h"
#include "comm/znx_array.h"
#include "comm/znx_string.h"
#include "comm/znx_handles.h"
#include "comm/znx_inet.h"


typedef struct {
    znx_str_t               listener_addr;
    znx_address_t           listener_address;
    int                     backlog;
    znx_bool_t              nodelay;
    znx_bool_t              quicack;
    znx_bool_t              reuseport;
    znx_bool_t              reuseaddr;
    znx_bool_t              ipv6only;
    znx_str_t               protocol;
    znx_bool_t              ssl;
    znx_bool_t              http2;
} znx_listener_conf_t;


typedef struct {
    // element is znx_listener_conf_t
    znx_array_t             *array;
    znx_pool_t              *pool;
    // save parser err.
    // the memory of err is applied from pool.
    znx_str_t               err;
} znx_listeners_conf_t;


static inline znx_listeners_conf_t *
znx_listeners_conf_create()
{
    znx_pool_t                  *pool;
    znx_listeners_conf_t        *conf;

    pool = znx_pool_create_ext(ZNX_POOL_MIN_PAGE_SIZE);
    conf = znx_pool_calloc(pool, sizeof(znx_listeners_conf_t));
    conf->pool = pool;
    conf->array = znx_array_create(2, sizeof(znx_listener_conf_t));
    znx_pool_add_cleanup(conf->pool, znx_array_destroy_handle, conf->array);

    return conf;
}


static inline void
znx_listeners_conf_destroy(znx_listeners_conf_t *conf)
{
    znx_pool_destroy(conf->pool);
}


znx_bool_t
znx_listeners_conf_parse(znx_listeners_conf_t *conf,
    const char *filepath);

